package com.cls.business.service.impl;

import com.cls.common.entity.QueryRequest;
import com.cls.business.entity.ReviewDetail;
import com.cls.business.mapper.ReviewDetailMapper;
import com.cls.business.service.IReviewDetailService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;
import lombok.RequiredArgsConstructor;
import com.github.pagehelper.PageHelper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageInfo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.Arrays;
import java.util.List;

/**
 * 专家评审结果详细表 Service实现
 *
 * @author wandering
 * @date 2020-11-18 11:59:01
 */
@Service
@RequiredArgsConstructor
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class ReviewDetailServiceImpl extends ServiceImpl<ReviewDetailMapper, ReviewDetail> implements IReviewDetailService {

    @Override
    public PageInfo<ReviewDetail> findReviewDetails(QueryRequest request, ReviewDetail reviewDetail) {
        LambdaQueryWrapper<ReviewDetail> queryWrapper = new LambdaQueryWrapper<>();
        // TODO 设置查询条件
        PageHelper.startPage(request.getPageNum(), request.getPageSize());
        List<ReviewDetail> list= this.list(queryWrapper);
        PageInfo pageInfo = new PageInfo(list);
        return pageInfo;
    }

    @Override
    public List<ReviewDetail> findReviewDetails(ReviewDetail reviewDetail) {

	    LambdaQueryWrapper<ReviewDetail> queryWrapper = new LambdaQueryWrapper<>();
		// TODO 设置查询条件
        queryWrapper.orderByDesc(ReviewDetail::getCreateTime);
		return this.baseMapper.selectList(queryWrapper);
    }
    @Override
    public List<ReviewDetail> findReviewDetailsByReviewId(Long ReviewId) {
        LambdaQueryWrapper<ReviewDetail> queryWrapper = new LambdaQueryWrapper<>();
        // TODO 设置查询条件
        queryWrapper.eq(ReviewDetail::getReviewId,ReviewId);
        queryWrapper.orderByDesc(ReviewDetail::getCreateTime);
        return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createReviewDetail(ReviewDetail reviewDetail) {
        this.save(reviewDetail);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateReviewDetail(ReviewDetail reviewDetail) {
        this.saveOrUpdate(reviewDetail);
    }


    /**
    * 删除
    * @param ids
    */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteReviewDetails(String[] ids) {
        List< String > list = Arrays.asList(ids);
        this.removeByIds(list);
     }

}
